envelope()server()Text
HTML
Text
HTML
render() for an .Rmd file with R code resultsusethis::edit_rstudio_snippets()
snippet my_email
# library(emayili)
my_rmd_message <- envelope() |>
from("me@gmail.com") |>
to("${1:to_address}") |>
subject("${2:Subject}") |>
render("${3:my_email_rmd_file}.Rmd") |>
attachment("${4:myfilename}")
{fig-align=“center”, fig-alt=“red circle with line through it”}
Edit your .Renviron file by adding MY_EMAIL_PASSWORD = "thePassWd" with usethis::edit_r_environ()
{fig.alt = “password prompt”}
Set up 2-factor authentication and an app password
https://myaccount.google.com/security
Alternative specifically for Gmail
https://developers.google.com/gmail/api/quickstart/python
Create a new project if you don’t already have one at
https://console.developer.google.com
Choose a name for your project
Click the ENABLE APIS AND SERVICES option
Search for and select the Gmail API
https://developers.google.com/workspace/guides/create-credentials#desktop-app
{fig-align=“center”, fig-alt=“Screen with options for application type: Web app, Android, Chrome app, iOS, TVs, Desktop app, and UWP with Desktop app highlighted”}
via giphy.com
library(rvest)
the_html <- read_html("https://apis.machlis.com/sharonwx")
the_text <- html_text2(the_html)
the_text <- gsub('"', '', the_text, fixed = TRUE)
cat(the_text)The temperature at Sharon's weather station is 70.2°F (21.2°C) as of 09:10 PM ET on September 12. It feels like 71.5°F (21.9°C). The dew point is 69.3°F (20.7°C) with 97% humidity.
library(vroom)
library(dplyr)
library(lubridate)
high_temps <- vroom("asos_temps.csv", show_col_types = FALSE) |>
mutate(MonthStarting = floor_date(as.Date(valid), unit = "month")) |>
group_by(MonthStarting) |>
filter(tmpc == max(tmpc)) |>
slice(1) |>
ungroup() |>
rename(HighTemp = tmpc)
glimpse(high_temps)Rows: 20
Columns: 4
$ station <chr> "FAHS", "FAHS", "FAHS", "FAHS", "FAHS", "FAHS", "FAHS", …
$ valid <dttm> 2021-01-06 11:00:00, 2021-02-20 12:00:00, 2021-03-09 13…
$ HighTemp <dbl> 37, 35, 38, 35, 33, 34, 34, 37, 38, 39, 41, 37, 35, 37, …
$ MonthStarting <date> 2021-01-01, 2021-02-01, 2021-03-01, 2021-04-01, 2021-05…
library(ggplot2)
ggplot(high_temps, aes(x=MonthStarting, y=HighTemp)) +
geom_bar(stat="identity", color = "black", fill="#0072B2") +
theme_classic() +
xlab("Month") + ylab("") + ggtitle("Johannesburg Monthly High Temperatures", subtitle = "Data from https://mesonet.agron.iastate.edu/request/download.phtml?network=ZA__ASOS") +
theme(plot.title = element_text(size = 24))my_email_message_w_image <- gm_mime() |>
gm_to("testing@machlis.com") |>
gm_from("framinghamevents@gmail.com") |>
gm_subject("Temperatures in Johannesburg") |>
gm_html_body(paste0('<p>Attached is a CSV with hourly temperature readings in Johannesburg. Below is a graph of monthly highs.</p><br /><img src="hightemps"><p>Data from https://mesonet.agron.iastate.edu/request/download.phtml?network=ZA__ASOS</p>')) |>
gm_attach_file("asos_temps.csv") |>
gm_attach_file("images/monthly_high_temps.png", id = "hightemps")
gm_send_message(my_email_message_w_image)blastula https://pkgs.rstudio.com/blastula/
Outlook-specific with Microsoft365R: Send Outlook email and Teams messages with R
This GitHub repo: https://www.github.com/smach/RLadiesJohannesburg
Keep your passwords and tokens secure with the keyring package
My InfoWorld article on gmailr
Do More With R: https://bit.ly/domorewithR
Find me on Twitter: @sharon000